import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import VitePluginElementPlus from 'vite-plugin-element-plus'
import eslintPlugin from 'vite-plugin-eslint'

export default defineConfig((cmd) => {
    console.info('cmd', cmd) // { mode: 'development | production', command: 'serve | build' }
    return {
        plugins: [
            vue(),
            VitePluginElementPlus({
                useSource: false, // 为true时更新scss会更新所有库样式文件，引起卡顿
            }),
            eslintPlugin({
                fix: true, // 保存自动格式化
            }),
        ],
        resolve: {
            alias: {
                '~': path.resolve(__dirname, './'),
                '@': path.resolve(__dirname, 'src'),
            },
        },
        css: {
            preprocessorOptions: {
                scss: {
                    additionalData: `@use '${path.resolve(__dirname, 'src/assets/scss/variable.scss')}' as *;`,
                },
                less: {
                    additionalData: `@import '${path.resolve(__dirname, 'src/assets/scss/variable.less')}';`,
                },
            },
        },
        server: {
            open: true,
            proxy: {
                '/api': {
                    target: 'http://127.0.0.1:7777',
                    changeOrigin: true,
                    rewrite: (urlPath) => urlPath.replace(/^\/api/, ''),
                },
            },
        },
    }
})
